package usr 
{
	import data.XMLConfig;
	/**
	 * ...
	 * @author ...
	 */
	public class ServiseData 
	{
		private var tehnics:Array;
		public static var once:ServiseData;
		public static var READY:Boolean = false;
		public function ServiseData() 
		{
			try{
			testxml = XMLConfig.getServiceXML()[0];
			testxml.normalize();
			parseData(testxml);
			READY = true;
			}catch (e:Error) {
				READY = false;
			}
			once = this;
		}
		public static function getInstance():ServiseData {
			if (once) return once;
			else return new ServiseData();
		}
		private var testxml:XML;
					 
		private function parseData(xmlp:XML):void {
			tehnics = new Array();
			//var teh:WCTehnik = new WCTehnik();
			var count:Number = xmlp.servicers.children().length();
			for (var ii:Number = 0; ii < count; ii++ ) {
				var _xml:XML = xmlp.servicers.children()[ii];
				var rolelist:XMLList = _xml[0].roles;
				var arr:Array = new Array();
				var roleitem:XML;
				var rolearr:Array = new Array();
				for each(roleitem in rolelist.children()) {
					var _xml2:XMLList = xmlp.works.work.(@role_id == roleitem.attribute("id"));
					rolearr.push(parseInt(roleitem.attribute("id")));
					var item:XML;
					for each( item in _xml2) {
						arr.push(new Array(item.attribute("id"),item.attribute("descr")));
					}
				}
				tehnics.push(new WCTehnik(_xml.attribute("id"), _xml.attribute("pin"), rolearr, arr));
			}
		}
		
		public function getTehnikByID(id:Number):WCTehnik {
			var tk:WCTehnik;
			for each(tk in tehnics) {
				if (id == tk._id) return tk;
			}
			return null
		}
		public var currteh:WCTehnik;
		
	}

}